package com.qf.controller;


import com.qf.bean.AjaxMessage;
import com.qf.entity.Address;
import com.qf.entity.CourseShow;
import com.qf.service.IAddressService;
import com.qf.service.ICartService;
import com.qf.service.impl.AddressServiceImpl;
import com.qf.service.impl.CartServiceImpl;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lcx
 * @since 2020-09-03
 */
@RestController
@RequestMapping("/cart")
public class CartController {

    @Autowired
    ICartService cartService;
    @Autowired
    IAddressService addressService;

    @PostMapping("/get")
    public AjaxMessage GetCart(String token){
        AjaxMessage ajaxMessage=new AjaxMessage();
        Integer id = addressService.getId(token);
        List<CourseShow> allCart = cartService.getAllCart(id);
        ajaxMessage.setResult(allCart);
        ajaxMessage.setStatus(0);
        ajaxMessage.setMsg("success");
        return ajaxMessage;
    }
    @GetMapping("/add")
    public AjaxMessage addCart(String token,Integer cid){
        AjaxMessage ajaxMessage=new AjaxMessage();
        Integer uid = addressService.getId(token);
        cartService.addCartById(uid,cid);
        ajaxMessage.setStatus(0);
        ajaxMessage.setMsg("success");
        return ajaxMessage;
    }


}
